package io.github.uicdb.et.item_data;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.uicdb.et.selection.RandomSelection;
import net.minecraft.core.Holder;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;

import java.util.List;

public record ItemCurioModifierData(List<Holder<RandomSelection>> entries) {

    public static final Codec<ItemCurioModifierData> CODEC = RecordCodecBuilder.create(ins -> ins.group(
            RandomSelection.HOLDER_CODEC.listOf().fieldOf("entries").forGetter(o -> o.entries)
    ).apply(ins, ItemCurioModifierData::new));


    public static final StreamCodec<RegistryFriendlyByteBuf, ItemCurioModifierData> STREAM_CODEC = StreamCodec.composite(
            RandomSelection.STREAM_CODEC.apply(ByteBufCodecs.list()),
            ItemCurioModifierData::entries,
            ItemCurioModifierData::new
    );
}
